<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//自定义团队管理
class DefTeam extends CommonController {

	function __construct(){
		
		parent::__construct();
		$this->load->model('User/DefteamModel','CurModel');
		
	}
	
	
	//start
	/**
	* @name 获取列表
	* @param page ture char 页面
	* @param size ture char 数量
	* @return 成功返回1
	*/
	//end
	function get_list(){
		$user_id = $this->user_id;
		
		$filter = array('name');
		$arr = array(
			'filter'=>$filter
		);
		
		$result = parent::_get_list($arr);
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$list = $result['list'];
		
		$this->load->model('User/UserModel','UserModel');
		
		foreach($list as $key=>$val){
			
			$list[$key]['members_name'] = '';
			
			$members = $this->UserModel->ids_get_list($val['members']);
			if(!$members){
				continue;
			}
			
			foreach($members as $k=>$v){
				$userlist[] = $v['nickname'];
			}
			$list[$key]['members_name'] = implode(',',$userlist);
		}
		
		$result['list'] = $list;
		
		$this->data_out($result);
	}
	
	function info_out($info){
		
		return $info;
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function get_info(){
		$user_id = $this->user_id;
		
		$result = parent::_get_info();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->data_out($result);
	}
	
	//start
	/**
	* @name 添加信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function add(){
		
		if(!$this->check_priv('defteam_update|defteam_add')){
			$this->err_out(LANG_NOPRIV);
		}
		
		$data = $this->input->post('data',null,array());
		if(!is_array($data)){
			$this->err_out('数据错误');
		}
		$ids = array();
		
		foreach($data as $key=>$val){
			if(empty($val['name'])){
				continue;
			}
			
			$arr = array(
				'name'=>$val['name'],
				'members'=>isset($val['data'])?implode(',',$val['data']):''
			);
			$insert_id = $this->CurModel->add($arr);
			$ids[] = $insert_id;
		}
		
		
		$this->add_log("添加自定义团队【".implode(',',$ids)."】信息",'defteam');
		$this->data_out(1);
	}
	
	
	
	//start
	/**
	* @name 删除
	* @param id ture int ID
	* @return 成功返回1
	*/
	//end
	function del(){
		
		if(!$this->check_priv('defteam_del')){
			$this->err_out(LANG_NOPRIV);
		}
		
		$result = parent::_del();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		
		$this->add_log("删除自定义团队【{$result}】",'defteam');
		$this->data_out($result);
		
	}
	
	
}
